<script type="text/javascript">
    function TzzglManagerCtrl($scope, $http, modalService, CtrlUtil, $element, UploadService) {
        var ctrl = this
        CtrlUtil.build(ctrl, ':root/tzzgl/list')
        this.query = function () {
            ctrl.entities && (ctrl.entities.content = {})
            var p = CtrlUtil.getQueryParams(ctrl)
            $http.post(':root/tzzgl/list', p).success(function (r) {
                ctrl.entities = r;
            })
        }
        this.edit = function (item) {
            ctrl.add(item)
        }
        this.del = function (item) {
            modalService.confirm({
                content: '确定要删除团组织' + item.mc + '吗?',
                result: item
            }).then(function (r) {
                $http.post(':root/tzzgl/deleteTzz', r).success(function (R) {
                    modalService.succ('删除成功', 1500)
                    ctrl.query()
                })
            })

        }
        this.add = function (item) {
            var content = $element.find('[template]>[edit]').clone()
            var title = $element.find('[template]>[edit-title]').clone()
            var result = item, year = new Date().getFullYear(), _cc = {'dm': 3}
            result = result || {
                cc: _cc,
                sfyx: 1,
                jlny: year,
                changeCc: function () {
                    listLsbm(result.cc.dm);
                }
            };
            var listLsbm = function (ccdm) {
                $http.post(':root/tzzgl/lsbm', {cc: ccdm}).success(function (r) {
                    result.lsbms = r;
                    if (!result.lsbm || !result.lsbm.id) {
                        result.lsbm = r[0];
                    }
                });
            };
            listLsbm(result.cc.dm);
            if (!result.px) {
                $http.post(':root/tzzgl/px').success(function (r) {
                    result.px = r;
                });
            }
            if (item) {
                //查询改组织团员信息
                $http.post(':root/tzzgl/tyxx', {bmId: item.id}).success(function (r) {
                    result.tyxx = r;
                });
                result.showBranch = true;
            }

            modalService.confirm({
                title: title,
                content: content,
                size: 'lg',
                titleCls: '',
                result: result,
                $scope: $scope,
                validator: function (r) {

                }
            }, {
                backdrop: false
            }).then(function (r) {
                $http.post(':root/tzzgl/addBm', r).success(function (R) {
                    modalService.succ(item ? '修改成功' : '添加成功', 1500);
                    if (!result.tyxx) {
                        ctrl.add(R);
                    } else {
                        ctrl.query();
                    }

                })
            })
        }
    }

</script>
<div ng-controller="TzzglManagerCtrl as ctrl" ng-init="ctrl.query()">
    <!-- Search area -->
    <div class="panel panel-cys">
        <div class="panel-heading">
            <h3 class="panel-title">
                <span class="glyphicon glyphicon-search"></span> 信息查询
            </h3>
        </div>
        <div class="panel-body">
            <div class="container-fluid">
                <form class="form-horizontal">
                    <div class="form-group col-md-4 remove-margin-horizontal">
                        <div class="col-md-10 col-md-offset-1">
                            <input placeholder="名称" ng-model="ctrl.mcQueryParam" type="text" class="form-control">
                        </div>
                    </div>
                    <div class="form-group col-md-4 remove-margin-horizontal">
                        <div class="col-md-10 col-md-offset-1">
                            <select chosen ng-model="ctrl.ccQueryParam" class="form-control">
                                <option value="">层次</option>
                                <option value="1">总支</option>
                                <option value="2">支部</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group col-md-4 remove-margin-horizontal">
                        <div class="col-md-10 col-md-offset-1">
                            <select chosen ng-model="ctrl.sfyxQueryParam" class="form-control">
                                <option value="">是否有效</option>
                                <option value="1">是</option>
                                <option value="0">否</option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group col-md-4 remove-margin-horizontal">
                        <div class="col-md-10 col-md-offset-1">
                            <div class="form-control-static">&nbsp;</div>
                        </div>
                    </div>
                </form>
                <div class="row pull-right">
                    <div class="col-md-12">
                        <button ng-click="ctrl.query()" type="submit" class="btn btn-cys btn-sm">
                            <span class="glyphicon glyphicon-search"></span>
                            查询
                        </button>
                        <button ng-click="ctrl.reset()" type="reset" class="btn btn-default btn-sm">
                            <span class="glyphicon glyphicon-repeat"></span>
                            重置
                        </button>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <!-- Search area END -->

    <!-- operation area -->
    <a type="button" class="btn btn-cys btn-sm" ng-click="ctrl.add()">
        <span class="glyphicon glyphicon-plus"></span>
        新增
    </a>
    <a type="button" class="btn btn-cys btn-sm" ng-click="export(ctrl,'root/course/exportCourse')">
        <span class="glyphicon glyphicon-export"></span>
        批量删除
    </a>
    <div class="pull-right" ng-include="':root/components/page.html'"></div>
    <!-- operation area END -->
    <!-- data grid area -->
    <div style="padding-top: 10px;">
        <table class="table table-bordered table-hover table-striped">
            <tr>
                <th>
                    <input ng-change="ctrl.checkAll(ctrl.$checkAll)" ng-model="ctrl.$checkAll" type="checkbox"/>
                </th>
                <th>名称</th>
                <th>层次</th>
                <th>隶属</th>
                <th>是否有效</th>
                <th>类别</th>
                <th>排序</th>
                <th>操作</th>
            </tr>
            <tr ng-repeat="item in ctrl.entities.content">
                <td><input ng-model="item.$checked" type="checkbox"/></td>
                <td>{{item.mc}}</td>
                <td>{{item.cc.mc}}</td>
                <td>{{item.lsbm.mc}}</td>
                <td>{{item.sfyx|toBool}}</td>
                <td>{{item.lb.mc}}</td>
                <td>{{item.px}}</td>
                <td>
                    <a href="javascript:;" ng-click="ctrl.edit(item)">编辑</a>
                    <a href="javascript:;" ng-click="ctrl.del(item)">删除</a>
                </td>
            </tr>
        </table>
        <p>
            共有记录：
            <span>{{ctrl.entities.totalElements}}</span> 条
        </p>
    </div>
    <!-- data grid area END -->
    <div ng-non-bindable template class="hidden">
        <h3 class="panel-title" edit-title>
            <span class="glyphicon glyphicon-search"></span> 团组织新增
        </h3>
        <div edit>
            <div class="panel-body">
                <form class="form-horizontal" ng-if="result">
                    <div class="row">
                        <div class="form-group">
                            <label class="col-md-2 control-label">名称:</label>
                            <div class="col-md-4">
                                <input ng-model="result.mc" name="result.mc" placeholder="请输入团组织名称" title="请输入团组织名称"
                                       type="text" class="form-control">
                            </div>
                            <label class="col-md-2 control-label">层次:</label>
                            <div class="col-md-4 radio">
                                <label>
                                    <input type="radio" ng-change="result.changeCc()" name="result.cc.dm" value="3"
                                           placeholder="" ng-model="result.cc.dm">
                                    总支
                                </label>
                                <label>
                                    <input type="radio" ng-change="result.changeCc()" value="4" name="result.cc.dm"
                                           placeholder="" ng-model="result.cc.dm">
                                    支部
                                </label>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-md-2 control-label">隶属:</label>
                            <div class="col-md-4">
                                <select class="form-control" ng-model="result.lsbm.id"
                                        ng-options="t.id as t.mc for t in result.lsbms">
                                </select>
                            </div>
                            <label class="col-md-2 control-label">是否有效:</label>
                            <div class="col-md-4 radio">
                                <label>
                                    <input type="radio" name="result.sfyx" value="0" placeholder=""
                                           ng-model="result.sfyx">
                                    否
                                </label>
                                <label>
                                    <input type="radio" value="1" name="result.sfyx" placeholder=""
                                           ng-model="result.sfyx">
                                    是
                                </label>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-md-2 control-label">建立年份:</label>
                            <div class="col-md-4">
                                <input ng-model="result.jlny" name="result.jlny" placeholder="请输入建立年份" title="请输入建立年份"
                                       type="text" class="form-control">
                            </div>
                            <label class="col-md-2 control-label">失效日期:</label>
                            <div class="col-md-4">
                                <input ng-model="result.sxrq" name="result.sxrq" datetimepicker placeholder="请输入失效日期"
                                       title="请输入失效日期" type="text" class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-md-2 control-label">类别:</label>
                            <div class="col-md-4">
                                <data entity="Lb" auto-load="true" after-refresh="lbs=data">
                                    <filter field="sfyx" value="1"></filter>
                                </data>
                                <select class="form-control" ng-model="result.lb.dm"
                                        ng-options="t.dm as t.mc for t in lbs">
                                    <option value="">请选择类别</option>
                                </select>
                            </div>
                            <label class="col-md-2 control-label">排序:</label>
                            <div class="col-md-4">
                                <input ng-model="result.px" name="result.px" placeholder="请输入排序" title="请输入排序"
                                       type="text" class="form-control">
                            </div>
                        </div>
                    </div>
                    <div ng-show="result.showBranch">
                        <div class="row">
                            <div layout="row" layout-align="center center">
                                <h4><label>支部书记</label></h4>
                            </div>
                        </div>
                        <div class="row">
                            <data bind-ctrl="ctrl.stuxh" auto-load="true" entity="Student">
                                <filter field="xh" operator="like" value="'%'+result.tyxx.xh+'%'"/>
                            </data>
                            <data bind-ctrl="ctrl.stuname" auto-load="true" entity="Student">
                                <filter field="name" operator="like" value="'%'+result.tyxx.xm+'%'"/>
                            </data>
                            <div class="form-group">
                                <label class="col-md-2 control-label">学号:</label>
                                <div class="col-md-4">
                                    <md-autocomplete md-no-cache="true" md-selected-item="result.tyxx"
                                                     md-search-text="ctrl.xhSearchText"
                                                     md-search-text-change="ctrl.stuxh.setFilter('xh','%'+ctrl.xhSearchText+'%','like')"
                                                     md-items="item in ctrl.stuxh.queryPage()" md-item-text="item.xh"
                                                     md-min-length="0" placeholder="输入学号搜索">
                                        <md-item-template>
                                            <span md-highlight-text="ctrl.xhSearchText" md-highlight-flags="^i">{{item.xh}}</span>
                                        </md-item-template>
                                        <md-not-found>
                                            没有找到学生
                                        </md-not-found>
                                    </md-autocomplete>
                                    </td>
                                </div>
                                <label class="col-md-2 control-label">姓名:</label>
                                <div class="col-md-4">
                                    <md-autocomplete md-no-cache="true" md-selected-item="result.tyxx"
                                                     md-search-text="ctrl.nameSearchText"
                                                     md-search-text-change="ctrl.stuname.setFilter('name','%'+ctrl.nameSearchText+'%','like')"
                                                     md-items="item in ctrl.stuname.queryPage()"
                                                     md-item-text="item.name" md-min-length="0" placeholder="输入姓名搜索">
                                        <md-item-template>
                                            <span md-highlight-text="ctrl.nameSearchText" md-highlight-flags="^i">{{item.name}}</span>
                                        </md-item-template>
                                        <md-not-found>
                                            没有找到学生
                                        </md-not-found>
                                    </md-autocomplete>
                                    </td>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="form-group">
                                <label class="col-md-2 control-label">性别:</label>
                                <div class="col-md-4">
                                    <input ng-model="result.tyxx.sexString" readonly="true" name="result.tyxx.sexString"
                                           type="text" class="form-control">
                                </div>
                                <label class="col-md-2 control-label">出生日期:</label>
                                <div class="col-md-4">
                                    <input ng-model="result.tyxx.birthdate" readonly="true" datetimepicker
                                           name="result.tyxx.birthdate" placeholder="请输入出生日期" title="请输入出生日期"
                                           type="text" class="form-control">
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="form-group">
                                <label class="col-md-2 control-label">民族:</label>
                                <div class="col-md-4">
                                    <input ng-model="result.tyxx.ethnicGroup.name" readonly="true"
                                           name="result.tyxx.ethnicGroup.name" placeholder="请输入民族" title="请输入民族"
                                           type="text" class="form-control">
                                </div>
                                <label class="col-md-2 control-label">文化程度:</label>
                                <div class="col-md-4">
                                    <input ng-model="result.tyxx.whcd.mc" readonly="true" name="result.tyxx.whcd.mc"
                                           placeholder="请输入文化程度" title="请输入文化程度" type="text" class="form-control">
                                </div>
                            </div>
                        </div>
                    </div>


                </form>
            </div>
        </div>
    </div>
</div>